﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Abp.EntityFrameworkCore;
using LZ.DCode.Configuration;
using LZ.DCode.Web;

namespace LZ.HzStorage.EntityFrameworkCore
{
    public abstract class DbContextFactory<T> : IDesignTimeDbContextFactory<T> where T : AbpDbContext
    {
        public abstract string ConnectionStringName { get; }
        public abstract T CreateDbContext(DbContextOptions<T> options);
        public T CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<T>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());
            HzStorageDbContextConfigurer.Configure(
                builder,
                configuration.GetConnectionString(ConnectionStringName)
            );
            return this.CreateDbContext(builder.Options);
        }   

        //public HzStorageDbContext CreateDbContext(string[] args)
        //{
        //    var builder = new DbContextOptionsBuilder<HzStorageDbContext>();
        //    var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

        //    HzStorageDbContextConfigurer.Configure(builder, configuration.GetConnectionString(HzStorageConsts.ConnectionStringName));

        //    return new HzStorageDbContext(builder.Options);
        //}
    }
}

